var express = require('express');
var less = require('less-middleware');
var dust4j = require('dustjs-middleware');
var path = require('path');
var alive = require('./alive');

var app = express();

var publicDir = __dirname + '/public';

app.use('^/css/gbk/*\.css', function(req, res, next) {
  res.contentType('text/css; charset=gbk');
  next();
});

app.use('/alive.html', alive());

app.use(less(publicDir, {
  encoding: 'gbk'
}));

app.use(dust4j(publicDir, {
  format: true,
  encoding: 'utf8'
}));

app.use(express.static(publicDir));

var host = process.env.VCAP_APP_HOST || 'localhost';
var port = process.env.VMC_APP_PORT || 80;
app.listen(port, host);